package cn.hx.admin.controller;

import cn.hx.admin.entity.WarningMessage;
import cn.hx.admin.service.WarningMessageService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (WarningMessage)表控制层
 *
 * @author makejava
 * @since 2023-12-11 10:07:36
 */
@RestController
@RequestMapping("warningMessage")
public class WarningMessageController {
    /**
     * 服务对象
     */
    @Resource
    private WarningMessageService warningMessageService;

    /**
     * 分页查询
     *
     * @param warningMessage 筛选条件
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<List<WarningMessage>> queryByPage(WarningMessage warningMessage) {
        return ResponseEntity.ok(this.warningMessageService.queryByPage(warningMessage));
    }

    /**
     * 查当日
     * @param warningMessage
     * @return
     */
    @GetMapping("/curDate")
    public ResponseEntity<List<WarningMessage>> queryByCurDate(WarningMessage warningMessage) {
        return ResponseEntity.ok(this.warningMessageService.queryByCurDate(warningMessage));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<WarningMessage> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.warningMessageService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param warningMessage 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<WarningMessage> add(@RequestBody WarningMessage warningMessage) {
        return ResponseEntity.ok(this.warningMessageService.insert(warningMessage));
    }

    /**
     * 编辑数据
     *
     * @param warningMessage 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<WarningMessage> edit(WarningMessage warningMessage) {
        return ResponseEntity.ok(this.warningMessageService.update(warningMessage));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.warningMessageService.deleteById(id));
    }

}

